﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.OData.Builder;
using System.Web.OData.Extensions;
//using Microsoft.Data.Edm;
using FamilyJobsUI.DB1;

namespace FamilyJobsUI
{
    public class WebAPIConfig
    {

        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            //config.MapODataServiceRoute("odata", "odata", model: GetModel());

            // New code:
            //ODataModelBuilder builder = new ODataConventionModelBuilder();
            //builder.EntitySet<T_Users>("T_Users");
            //builder.EntitySet<T_UserPoints>("T_UserPoints");
            //builder.EntitySet<T_PointTypes>("T_PointTypes");
            //config.MapODataServiceRoute(
            //    routeName: "ODataRoute",
            //    routePrefix: null,
            //    model: builder.GetEdmModel());

        }

        public static Microsoft.OData.Edm.IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet<FamilyJobsUI.DB1.T_UserPoints>("UserPoints");

            //EntitySetConfiguration<Person> persons = builder.EntitySet<Person>("Person");

            //FunctionConfiguration myFirstFunction = persons.EntityType.Collection.Function("MyFirstFunction");
            //myFirstFunction.ReturnsCollectionFromEntitySet<Person>("Person");

            return builder.GetEdmModel();
        }

        //public static void RegisterAPIRoutes(HttpConfiguration config)
        //{
        //    config.MapHttpAttributeRoutes();
        //} 
    }
}